﻿@*YoursLC有源低代码 Create:φ创建者Creatorφ 2022-05-07 19:30:42 弹出选择树-此文件放置于Views/Demo03/中*@

@using Think9.Models;
@{ ViewBag.Title = "Index";
	Layout = "~/Areas/Shared/_LayuiForm.cshtml"; }

<input style="display:none" id="sys_flag" value="SubTable03v4">
<input style="display:none" id="Pu_from" value="@ViewBag.PuFrom">
<input style="display:none" id="Pu_tbid" value="@ViewBag.PuTbId">
<input style="display:none" id="Pu_indexid" value="@ViewBag.PuIndexId">
<input style="display:none" id="Pu_id" value="@ViewBag.PuId">
<input style="display:none" id="Pu_v" value="@ViewBag.PuV">

<table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>

<script>
	layui.config({
		base: '/self_js/' /*自定义的js文件 位于wwwroot/self_js文件夹中*/
	});
	layui.use(["table", "form", "exLayer", "exUtils", "Demo03"], function () {
		let table = layui.table;
		let form = layui.form;
		let exLayer = layui.exLayer;
		let exUtils = layui.exUtils;
		let mySelf = layui.Demo03;

		let $ = layui.$;

		form.render(); 

		let ThisTable = table.render({
			elem: "#tableId",
			url: "/Demo03/GetPopUpTablePageList?indexid=" + $('#sys_flag').val() + "&from=" + $('#Pu_from').val(),
			method:"POST",
			defaultToolbar: [ 'filter', 'exports'],
			toolbar: "#toolbarTpl",
			cols: [[
			{ type: "radio" }

			   , { field: "Value", title: "编码" }
			   , { field: "Text", title: "名称" }
			]],
			done: function (res, curr, count) {
			}
		});

		 //查询
		form.on("submit(search)", function (data) {
			$("#searchfield").hide();
			var _list = [];
			getControlSearch(_list);

			ThisTable.reload({
				where: { flag: $('#sys_flag').val(), "list": _list },
				page: { curr: 1 }
			});
			return false;
		});


		table.on("toolbar(tableFilter)", function (obj) {
			switch (obj.event) {
				case "OK":
					getPopUpSelect(obj);
					break;
				case "searchShow":
					mySelf.searchShow();
					break;
			}
		});

		function getPopUpSelect(obj) {
			var strv = '';
			var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
			if (checkStatus.data.length > 0) {
				strv = checkStatus.data[0].Value;
			}

			//为父页面控件赋值
			$(window.parent.document).find('#Pu_value').val(strv);//选择的值
			$(window.parent.document).find('#Pu_tbid').val($('#Pu_tbid').val());//表id
			$(window.parent.document).find('#Pu_indexid').val($('#Pu_indexid').val());//指标编码
			$(window.parent.document).find('#Pu_id').val($('#Pu_id').val());//子表弹出时使用 对应table中id 行
			$(window.parent.document).find('#Pu_v').val($('#Pu_v').val());//子表弹出时使用 第几列

			$(window.parent.document).find('#Pu_value').click();//调用父页面事件 完成控件赋值及数据读取

			parent.layer.close(parent.layer.getFrameIndex(window.name));
		}

		//从查询控件读值 后台解析查询条件
		function getControlSearch(_list) {
			var _row = { ClassID: $('#sys_flag').val(), Text: $('#dictid').val(), Value:'dictid'};
			_list.push(_row);
		}

	});
</script>
<!-- 头工具栏模板 -->
<script type="text/html" id="toolbarTpl">
	<button class="layui-btn layui-btn-normal layui-btn-sm" lay-event="OK" id="OK">确定选择</button>
</script>